package com.ny.view;

import com.ny.entity.Manager;
import com.ny.entity.Student;
import com.ny.service.ManagerService;
import com.ny.service.StudentService;
import com.ny.service.impl.ManagerServiceImpl;
import com.ny.service.impl.StudentServiceImpl;

import java.sql.SQLException;
import java.util.Scanner;

public class ViewMain {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        StudentService service = new StudentServiceImpl();
        ManagerService service1 = new ManagerServiceImpl();
        Student student = new Student();
        Manager manager = new Manager();
        System.out.println("欢迎来到校园商品售卖管理系统");
        boolean flag = true;
        while (flag){
            System.out.println("1.注册账号");
            System.out.println("2.登录账号");
            System.out.println("3.管理员登陆账号");
            System.out.println("4.退出系统");
            System.out.println("请输入你的选择：");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("欢迎来到注册系统");
                    System.out.println("请输入用户名");
                    String username = scanner.next();
                    System.out.println("请输入密码");
                    String password = scanner.next();
                    System.out.println("请输入手机号");
                    String phone = scanner.next();
                    student.setStudentName(username);
                    student.setStudentPassword(password);
                    student.setStudentPhone(phone);
                    int add = service.add(student);
                    if (add>0){
                        System.out.println("注册成功");
                    }else {
                        System.out.println("注册失败");
                    }
                    break;
                case 2:
                    System.out.println("用户登录");
                    System.out.println("请输入用户名");
                    String studentName = scanner.next();
                    System.out.println("请输入密码");
                    String studentPassword = scanner.next();
                    // 调用业务层的登录功能：
                    student= service.login(studentName, studentPassword);
                    if(student != null){
                        System.out.println("登录成功");
                        IndexView indexView = new IndexView();
                        indexView.indexView(student);
                    }
                    else {
                        System.out.println("登录失败");
                    }
                    break;
                case  3:
                    System.out.println("请输入用户名");
                    String managername1 = scanner.next();
                    System.out.println("请输入密码");
                    String managerpwd1 = scanner.next();
                    manager.setManagerName(managername1);
                    manager.setManagerPassword(managerpwd1);
                    manager= service1.login1(managername1, managerpwd1);
                    if(manager != null){
                        System.out.println("登录成功");
                        ManagerView managerView = new ManagerView();
                        managerView.managerView(manager);
                    }
                    else {
                        System.out.println("登录失败");
                    }
                    break;
                case 4:
                    flag = false;
                    System.out.println("已退出");
                    break;
            }
        }
    }
}
